echo -n "aaabbbcccbbbcccaaa"|sed -r 's/(.)\1*/&\n/g;:a;s/(^|\n)(.*)(\n(.*\n)*)\2\n/\1\2\3/;ta'

seq 9|sed 'N;:a;N;s/\n/ /gp;s/\w //;ta'

sed 'N;N;s/\n/ /g' 1.txt

sed ':a;N;/ms$/{s/\n/ /;ta};P;D' 2.txt

sed '/^AA/s/$/ YES/;t;s/$/ NO/' 3.txt

sed '/^AA/ba;s/$/ NO/;b;:a;s/$/ YES/' 3.txt

sed -n '/a/{:a;N;/c/{/^\n/s/\n//;p;z};ba}' 4.txt

sed -r 's/&/\n1\n2\n3\n4\n5&/;:a;s/\n(.)(.*)&\1=([0-9]*)/\t\3\2/;ta;s/\n./\t0/g' 5.txt
